package cn.ac.iie.common.util.misc;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SimpleHash
{
  public static long getSimpleMD5(String val)
  {
    MessageDigest md5;
    try
    {
      md5 = MessageDigest.getInstance("SHA");
    } catch (NoSuchAlgorithmException e) {
      throw new RuntimeException("MD5 not supported", e);
    }
    md5.reset();
    byte[] keyBytes = null;
    try {
      keyBytes = val.getBytes("UTF-8");
    } catch (UnsupportedEncodingException ex) {
    }
    md5.update(keyBytes);
    byte[] digest = md5.digest();
    String s = new String(digest);
    return Math.abs(s.hashCode());
  }

  public static long getSimpleHash(String val)
  {
    return Math.abs(val.hashCode());
  }

  public static void main(String[] args) {
    long l = getSimpleHash("1231啊啊啊啊啊啊啊大双方都") % 32L;
    System.out.println(l);
  }
}